package org.springblade.modules.restaurant.wrapper;

import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.restaurant.entity.Task;
import org.springblade.modules.restaurant.service.IAreaService;
import org.springblade.modules.restaurant.vo.TaskVO;
import org.springblade.modules.system.service.IUserService;

import java.util.List;

/**
 * @author harry
 * @公众号 Harry技术
 */
public class TaskWrapper extends BaseEntityWrapper<Task, TaskVO> {
	private static final IAreaService areaService;
	private static final IUserService userService;

	static {
        areaService = org.springblade.core.tool.utils.SpringUtil.getBean(IAreaService.class);
        userService = org.springblade.core.tool.utils.SpringUtil.getBean(IUserService.class);
    }

    public static TaskWrapper build() {
        return new TaskWrapper();
    }
	@Override
	public TaskVO entityVO(Task entity) {
		TaskVO taskVO = BeanUtil.copyProperties(entity, TaskVO.class);

		List<String> areaName = areaService.getAreaNames(entity.getAreaIds());
		if (Func.isNotEmpty(areaName)) {
            taskVO.setAreaName(Func.join(areaName));
        }
		List<String> realName = userService.getRealNames(entity.getUserIds());
		if (Func.isNotEmpty(realName)) {
            taskVO.setRealName(Func.join(realName));
        }
        return taskVO;

	}
}
